using System;
using System.ComponentModel;

namespace teavch.Utilities.Electrical.Design.Gui.LineDiagram
{

	public partial class CapacitorBank : ElectricalSymbol
	{

		private float _heightRatio = .70f;
		private float _jointRatio = .25f;
    private float _jointGapRatio = .20f;

		public CapacitorBank()
		{
			InitializeComponent();
		}

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Height Ratio of the Capacitor Bank" )]
    public float HeightRatio
    {
      get { return this._heightRatio; }
      set
      {
        this._heightRatio = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Joint Ratio of the Capacitor Bank" )]
    public float JointRatio
    {
      get { return this._jointRatio; }
      set
      {
        this._jointRatio = value;
        this.Refresh();
      }
    }

    [Category( "Graphical Symbols for Single Line Diagrams" ), Description( "Get or set the Joint Gap Ratio of the Capacitor Bank" )]
    public float JointGapRatio
    {
      get { return this._jointGapRatio; }
      set
      {
        this._jointGapRatio = value;
        this.Refresh();
      }
    }


		protected override void OnPaint( System.Windows.Forms.PaintEventArgs e )
		{
			base.OnPaint( e );
			this.Paint( e );
		}
		
		protected override void OnResize( EventArgs e )
		{
			base.OnResize( e );
			this.ResizeNow( e );
		}

		private void ResizeNow( EventArgs ea )
		{
			this.Refresh();
		}

		private new void Paint( System.Windows.Forms.PaintEventArgs pea )
		{
      int hl1x1 = 0, hl1y1 = 0, hl1x2 = 0, hl1y2 = 0;
      int hl2x1 = 0, hl2y1 = 0, hl2x2 = 0, hl2y2 = 0;

      int vl1x1 = 0, vl1y1 = 0, vl1x2 = 0, vl1y2 = 0;
      int vl2x1 = 0, vl2y1 = 0, vl2x2 = 0, vl2y2 = 0;
      int vl3x1 = 0, vl3y1 = 0, vl3x2 = 0, vl3y2 = 0;
      int vl4x1 = 0, vl4y1 = 0, vl4x2 = 0, vl4y2 = 0;
      
      int jl1x1 = 0, jl1y1 = 0, jl1x2 = 0, jl1y2 = 0;
      int jl2x1 = 0, jl2y1 = 0, jl2x2 = 0, jl2y2 = 0;
      int jl3x1 = 0, jl3y1 = 0, jl3x2 = 0, jl3y2 = 0;
      int jl4x1 = 0, jl4y1 = 0, jl4x2 = 0, jl4y2 = 0;

			this.Width = ( int ) Math.Ceiling( this.SymbolSize + ( this.SymbolSize * this._jointRatio / 2 ) );

			this.Height = ( int ) ( ( this.SymbolSize * _heightRatio ) + 1 );

			hl1x1 = ( int ) ( ( this.SymbolSize * this._jointRatio ) / 2 );
			hl1y1 = 0;
			hl1x2 = this.SymbolSize;
			hl1y2 = 0;

      vl1x1 = hl1x1;
      vl1y1 = 0;
      vl1x2 = hl1x1;
      vl1y2 = ( int ) Math.Ceiling( ( this.Height - ( this.Height * this._jointGapRatio ) ) / 2 );

      jl1x1 = 0;
      jl1y1 = vl1y2;
			jl1x2 = ( int ) Math.Ceiling( this.SymbolSize * this._jointRatio );
      jl1y2 = vl1y2;

			vl2x1 = this.SymbolSize;
      vl2y1 = 0;
			vl2x2 = this.SymbolSize;
      vl2y2 = ( int ) Math.Ceiling( ( this.Height - ( this.Height * this._jointGapRatio ) ) / 2 );

			jl2x1 = ( int ) Math.Ceiling( this.SymbolSize - ( this.SymbolSize * this._jointRatio / 2 ) );
      jl2y1 = vl2y2;
			jl2x2 = ( int ) Math.Ceiling( this.SymbolSize + ( this.SymbolSize * this._jointRatio ) );
      jl2y2 = vl2y2;

			vl3x1 = this.SymbolSize;
      vl3y1 = ( int ) Math.Ceiling( vl2y2 + ( ( this.Height * this._jointGapRatio ) ) );
			vl3x2 = this.SymbolSize;
      vl3y2 = this.Height;

			jl3x1 = ( int ) Math.Ceiling( this.SymbolSize - ( this.SymbolSize * this._jointRatio / 2 ) );
      jl3y1 = ( int ) Math.Ceiling( vl2y2 + ( this.Height * this._jointGapRatio ));
			jl3x2 = ( int ) Math.Ceiling( this.SymbolSize + ( this.SymbolSize * this._jointRatio ) );
      jl3y2 = ( int ) Math.Ceiling( vl2y2 + ( this.Height * this._jointGapRatio ) );

      vl4x1 = vl1x1;
      vl4y1 = ( int ) Math.Ceiling( vl2y2 + ( ( this.Height * this._jointGapRatio ) ) );
      vl4x2 = vl1x1;
      vl4y2 = this.Height;

      jl4x1 = 0;
      jl4y1 = vl4y1;
			jl4x2 = ( int ) Math.Ceiling( this.SymbolSize * this._jointRatio );
      jl4y2 = vl4y1;

			hl2x1 = ( int ) ( ( this.SymbolSize * this._jointRatio ) / 2 );
      hl2y1 = ( int ) ( this.Height - 1 );
			hl2x2 = this.SymbolSize;
      hl2y2 = ( int ) ( this.Height - 1 );
			
      System.Drawing.Drawing2D.GraphicsPath _gpath = new System.Drawing.Drawing2D.GraphicsPath();
      _gpath.AddLine( hl1x1, hl1y1, hl1x2, hl1y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( vl1x1, vl1y1, vl1x2, vl1y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( jl1x1, jl1y1, jl1x2, jl1y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( vl2x1, vl2y1, vl2x2, vl2y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( jl2x1, jl2y1, jl2x2, jl2y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( vl3x1, vl3y1, vl3x2, vl3y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( jl3x1, jl3y1, jl3x2, jl3y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( vl4x1, vl4y1, vl4x2, vl4y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( jl4x1, jl4y1, jl4x2, jl4y2 );
      _gpath.CloseFigure();
      _gpath.AddLine( hl2x1, hl2y1, hl2x2, hl2y2 );
      pea.Graphics.DrawPath( this.Pen,_gpath );
		}
	}
}
